﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Ebook_Organizer.Library;

namespace Ebook_Organizer
{
    public partial class tabFileAnalizer : UserControl
    {
        private int totalfile = 0, minusfile = 0;
        public tabFileAnalizer()
        {
            InitializeComponent();
        }

        private void btnSource_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                txtSource.Text = fbd.SelectedPath;
            }
        }

        private void btnGo_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            FileAnalizer(txtSource.Text);
            this.Cursor = Cursors.Default;
        }

        private void FileAnalizer(string folder)
        {
            Catalogator.Clear();

            foreach (string file in Directory.GetFiles(folder))
            {
                totalfile++;
                string filename = Path.GetFileName(file);
                if (NameParser.ContainOneMinus(filename))
                {
                    minusfile++;
                    Catalogator.Add(filename.Split(new char[]{'-'}));
                }
                txtCopy.Text = filename;
                txtMinus.Text = minusfile.ToString();
                txtTotal.Text = totalfile.ToString();

                Application.DoEvents();
            }

            Catalogator.DisplayAuthor();

        }
    }
}
